package pers.twf.twfRpc.protocol;

import lombok.Getter;

@Getter
public enum ProtocolMessageTypeEnum {
    REQUEST(0),
    RESPONSE(1),
    HEART_BEAT(2),
    OTHERS(3);

    private int type;

    ProtocolMessageTypeEnum(int type) {
        this.type = type;
    }

    /**
     * 根据type获取枚举对象
     * @param type
     * @return
     */
    public static ProtocolMessageTypeEnum getEnumByType(int type) {
        for (ProtocolMessageTypeEnum protocolMessageTypeEnum : ProtocolMessageTypeEnum.values()) {
            if (protocolMessageTypeEnum.getType() == type) {
                return protocolMessageTypeEnum;
            }
        }
        return null;
    }
}
